<template>
<div>
  <van-image :src="defImg"></van-image>
  <van-cell-group title="用户信息">
    <van-cell title="商城号" :value="User.id" />
    <van-cell title="绑定手机号" :value="User.phone" />
    <van-cell title="绑定邮箱" :value="User.email" />
    <van-cell title="用户名" :value="User.uname" />
    </van-cell-group>
    <van-cell-group title="用户操作">
    <van-cell title="修改密码" @click="tochangepwd" value=">" />
    <van-cell title="退出登录" @click="exit" value=">" />
    </van-cell-group>
</div>
</template>

<script>
import { showDlg } from '../../utils/tools';
  import {removeStorageToken,getStorageUser,setStorageUser} from "@/utils/storage.js"//导入
import { Dialog } from "vant";
import request, { getUrl } from "../../utils/request";
  export default{
    name:"user",
    data(){
      return {
        defImg:require("@/assets/images/avatar_default.png"),//默认头像
        User:{
          id:-1,
          phone:"13988888888",
          email:"abc@abc.com",
          uname:"Admin"
        }
      }
    },
    created() {//页面创建后，把发起请求把数据渲染上去
      request({//发起request请求
        url:getUrl("User/getUserInfoById"),//URL
        method:"get",//请求方法
        params:{//Post传data，get请求传params
          id:getStorageUser().id
        }
      }).then(res=>{//成功回调
          this.User=res.data.data
      }).catch(res=>{//失败回调
        showDlg('错误提醒','网络错误！')
      })
    },
    methods:{
      tochangepwd:function(){//跳转到修改密码
        this.$router.push("/changepwd")
      },
      exit:function(){
        removeStorageUser()//清除用户信息
        this.$router.push("/login")//路由跳转
      }
    }
  }
</script>

<style>
</style>
